package com.livemeter;

import java.sql.Timestamp;


/*
 * Class represents on meter value in a specific moment of time.
 * */
public class MeterValue 
{
	public MeterValue(int valuePercentile10, int valuePercentile90,
					int valueAverage, int valueLocalMeter, long timeOfValue,int userCount) 
	{
		this.valuePercentile10 = valuePercentile10;
		this.valuePercentile90 = valuePercentile90;
		this.valueAverage = valueAverage;
		this.valueLocalMeter = valueLocalMeter;
		this.timeOfValue = timeOfValue;
		this.userCount = userCount;
	}
	// Copy constructor
	public MeterValue(MeterValue other)
	{
		this(other.valuePercentile10,other.valuePercentile90,other.valueAverage,other.valueLocalMeter,other.timeOfValue,other.userCount);
	}
	
	boolean isEqualTo(MeterValue other,boolean ignoreTime)
	{
		return (this.valueAverage == other.valueAverage) && (this.valuePercentile10 == other.valuePercentile10) &&
				(this.valuePercentile90 == other.valuePercentile90) && (this.valueLocalMeter == other.valueLocalMeter)
				&& (ignoreTime || (this.timeOfValue == other.timeOfValue));
	}

	public String toString()
	{
		Timestamp ts = new Timestamp(timeOfValue);
		return 	String.valueOf(valuePercentile10)+":"+
				String.valueOf(valueAverage)+":"+
				String.valueOf(valuePercentile90)+" / "+
				String.valueOf(valueLocalMeter)+" # "+
				String.valueOf(userCount)+" @ "+ts.toString();
	}

	//values
	private int valuePercentile10;
	private int valuePercentile90;
	private int valueAverage;
	
	private int valueLocalMeter; //value of local client at that time
	private int userCount;

	//time as ms since epoch
	private long timeOfValue;
	
	public int getValuePercentile10() {
		return valuePercentile10;
	}

	public int getValuePercentile90() {
		return valuePercentile90;
	}

	public int getValueAverage() {
		return valueAverage;
	}

	public int getValueLocalMeter() {
		return valueLocalMeter;
	}
	
	public void setValueLocalMeter(int localValue)
	{
		valueLocalMeter = localValue;
	}

	public long getTime() {
		return this.timeOfValue;
	}

	public void setTime(long time) {
		this.timeOfValue = time;
	}

	public Timestamp getTimestamp() {
		return new Timestamp(this.timeOfValue);
	}
	public void setTimestamp(Timestamp ts) {
		this.timeOfValue = ts.getTime();
	}

}
